package br.gov.cemaden.library.repository.alerta;

import br.gov.cemaden.library.model.alerta.Aerodromo;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;

/**
 *
 * @author alan
 */
public class AerodromoRepository {
    
    private EntityManager em;    
    
    public AerodromoRepository(EntityManager em){
        this.em = em;
    }    
    
    public List<Aerodromo> list(){
        try{
            return em.createQuery("from Aerodromo").getResultList();
        }
        catch(NoResultException ex){
            return null;
        }
    }
    
    public Aerodromo persist(Aerodromo aerodromo){
        em.getTransaction().begin();
        em.persist(aerodromo);
        em.getTransaction().commit();
        return aerodromo;
    }    
    
}